package com.woniu.Utils;

import org.springframework.format.annotation.DateTimeFormat;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAccessor;
import java.util.Date;

public class GetNetWorkTime {

    public static Date getTime() throws IOException {
        String webUrl = "http://www.ntsc.ac.cn";
        URL url= new URL(webUrl);//取得资源对象
        URLConnection urlConnection= url.openConnection();//生成连接对象
        urlConnection.connect();//发出连接
        long ld= urlConnection.getDate();
        Date date=new Date(ld);
        Instant instant=date.toInstant();
        DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(ld), ZoneId.systemDefault());
        return date;
    }
}
